//
// Created by chizuru on 2025/9/4.
//

#include "TransactionCommandBatchRead.h"
#include "ICommand.h"
#include "RegisterReadCommand.h"
#include "Invoker.h"

using std::unique_ptr;
using std::make_unique;
using std::pair;
using std::vector;
TransactionCommandBatchRead::TransactionCommandBatchRead(CameraDevice &comm,
                                                         const std::vector<std::pair<uint16_t, uint32_t>> &ops,
                                                         RetryPolicy rp) : ITransactionCommand(comm, ops, rp) {

}

OperationResult TransactionCommandBatchRead::execute() {
    vector<unique_ptr<camera_link_bobcat::ICommand>> readCmds;
    for (auto& [addr, value]: ops) {
        readCmds.push_back(make_unique<RegisterReadCommand>(comm, addr, &value, rp));
    }

    return camera_link_bobcat::Invoker::executeWithRollback(readCmds);
}
